﻿@using System.Linq

@inherits RadzenComponent

@if (Items != null)
{
    <CascadingValue Value=this>
        @Items
    </CascadingValue>
}
@if (Visible)
{
<div @ref="@Element" role="tablist" style=@Style @attributes="Attributes" class="@GetCssClass()" id="@GetId()">
    @for (var i = 0; i < items.Count; i++)
    {
        var item = items[i];    
        if (!item.Visible)
            continue;

        <div @ref="@item.Element" id="@item.GetItemId()" @attributes="item.Attributes" class="@item.GetItemCssClass()" style="@item.Style">
            <a @onclick="@((args) => SelectItem(item))" aria-label="@ItemAriaLabel(i, item)" title="@ItemTitle(i, item)"  href="javascript:void(0)" role="tab" tabindex="0"
               id="@($"rz-accordiontab-{items.IndexOf(item)}")" aria-controls="@($"rz-accordiontab-{items.IndexOf(item)}-content")" aria-expanded="true">
                @if (IsSelected(i, item))
                {
                    <span class="rz-accordion-toggle-icon rzi rzi-chevron-down"></span>
                }
                else
                {
                    <span class="rz-accordion-toggle-icon rzi rzi-chevron-right"></span>
                }
                @if (!string.IsNullOrEmpty(item.Icon))
                {
            <i class="rzi" style="@(!string.IsNullOrEmpty(item.IconColor) ? $"color:{item.IconColor}" : null)">@((MarkupString)item.Icon)</i>
                }
                @if (!string.IsNullOrEmpty(item.Text))
                {
                    <span>@((MarkupString)item.Text)</span>
                }
            </a>
        </div>
        @if (IsSelected(i, item))
        {
            <div class="rz-accordion-content-wrapper" role="tabpanel"
                 id="@($"rz-accordiontab-{items.IndexOf(item)}-content")" aria-hidden="false" aria-labelledby="@($"rz-accordiontab-{items.IndexOf(item)}")">
                <div class="rz-accordion-content ">
                    @item.ChildContent
                </div>
            </div>
        }
    }
</div>
}